home *** CD-ROM | disk | FTP | other *** search
- package com.simeda.ActiveViewer;
-
- import java.io.IOException;
- import java.util.Vector;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- class vncCanvas extends Canvas {
- rfbProto rfb = null;
- Image paintImage;
- Graphics pig;
- Graphics pig2;
- boolean needToResetClip;
- boolean isRunning = true;
- Command disconnectCommand = null;
- Command textCommand = null;
- Command cursorCommand = null;
- Command imageCommand = null;
- Command arrowCommand = null;
- Command numericCommand = null;
- Command textAreaCommand = null;
- Command specialCharsCommand = null;
- TextArea textArea;
- SpecialChars specialCharsList;
- boolean isCtrlPressed;
- boolean isAltPressed;
- boolean isMetaPressed;
- Command pressCtrl;
- Command pressAlt;
- Command pressMeta;
- Command releaseCtrl;
- Command releaseAlt;
- Command releaseMeta;
- VNCController parent = null;
- private Vector _status = new Vector();
- KeyReader keyReader;
- public static final int CURSOR = 1;
- public static final int TEXT = 2;
- public static final int IMAGE = 3;
- public static final int ARROW = 4;
- public static final int NUMERIC = 5;
- public static final int TEXTAREA = 6;
- int keyMode = 1;
- int deltaX = 0;
- int deltaY = 0;
- boolean incremental;
- public char currentLetter = '\uffff';
- int cursorX;
- int cursorY;
- int cursorButton;
-
- public int toRGB(int var1) {
- int var2 = (var1 & 7) * 255 / 7;
- int var3 = (var1 >> 3 & 7) * 255 / 7;
- int var4 = (var1 >> 6 & 3) * 255 / 3;
- return (var2 << 16) + (var3 << 8) + var4;
- }
-
- public void status(String var1) {
- this._status.addElement(var1);
- ((Canvas)this).repaint();
- ((Canvas)this).serviceRepaints();
- }
-
- vncCanvas(VNCController var1) throws IOException {
- this.parent = var1;
- this.disconnectCommand = new Command("Disconnect", 4, 1);
- this.cursorCommand = new Command("Move cursor", 4, 1);
- this.imageCommand = new Command("Move image", 4, 1);
- this.arrowCommand = new Command("Send arrows", 4, 1);
- this.textCommand = new Command("Character keypad", 4, 1);
- this.numericCommand = new Command("Numeric keypad", 4, 1);
- this.textAreaCommand = new Command("Show text area", 4, 1);
- this.specialCharsCommand = new Command("Special characters", 4, 1);
- this.pressCtrl = new Command("Press CTRL", 4, 1);
- this.pressAlt = new Command("Press ALT", 4, 2);
- this.pressMeta = new Command("Press META", 4, 3);
- this.releaseCtrl = new Command("Release CTRL", 4, 1);
- this.releaseAlt = new Command("Release ALT", 4, 2);
- this.releaseMeta = new Command("Release META", 4, 3);
- }
-
- public void doInit(rfbProto var1) throws IOException {
- System.out.println("Doing init");
- this.rfb = var1;
- this.textArea = new TextArea(this);
- this.specialCharsList = new SpecialChars(this);
- this.keyReader = new KeyReader(var1, this);
- this.rfb.writeSetPixelFormat(8, 8, false, true, 7, 7, 3, 0, 3, 6);
- this.paintImage = Image.createImage(((Canvas)this).getWidth(), ((Canvas)this).getHeight());
- this.pig = this.paintImage.getGraphics();
- System.out.println("HAS POINTER EVENTS " + ((Canvas)this).hasPointerEvents());
- System.out.println("HAS POINTER MOTION EVENTS " + ((Canvas)this).hasPointerMotionEvents());
- System.out.println("HAS REPEAT EVENTS " + ((Canvas)this).hasRepeatEvents());
- }
-
- public void doCommands() {
- ((Displayable)this).removeCommand(this.disconnectCommand);
- ((Displayable)this).removeCommand(this.cursorCommand);
- ((Displayable)this).removeCommand(this.imageCommand);
- ((Displayable)this).removeCommand(this.arrowCommand);
- ((Displayable)this).removeCommand(this.numericCommand);
- ((Displayable)this).removeCommand(this.textCommand);
- ((Displayable)this).removeCommand(this.textAreaCommand);
- ((Displayable)this).removeCommand(this.specialCharsCommand);
- ((Displayable)this).removeCommand(this.releaseCtrl);
- ((Displayable)this).removeCommand(this.pressCtrl);
- ((Displayable)this).removeCommand(this.releaseAlt);
- ((Displayable)this).removeCommand(this.pressAlt);
- ((Displayable)this).removeCommand(this.releaseMeta);
- ((Displayable)this).removeCommand(this.pressMeta);
- ((Displayable)this).addCommand(this.disconnectCommand);
- ((Displayable)this).addCommand(this.cursorCommand);
- ((Displayable)this).addCommand(this.imageCommand);
- ((Displayable)this).addCommand(this.arrowCommand);
- ((Displayable)this).addCommand(this.numericCommand);
- ((Displayable)this).addCommand(this.textCommand);
- ((Displayable)this).addCommand(this.textAreaCommand);
- ((Displayable)this).addCommand(this.specialCharsCommand);
- if (this.isCtrlPressed) {
- ((Displayable)this).addCommand(this.releaseCtrl);
- } else {
- ((Displayable)this).addCommand(this.pressCtrl);
- }
-
- if (this.isAltPressed) {
- ((Displayable)this).addCommand(this.releaseAlt);
- } else {
- ((Displayable)this).addCommand(this.pressAlt);
- }
-
- if (this.isMetaPressed) {
- ((Displayable)this).addCommand(this.releaseMeta);
- } else {
- ((Displayable)this).addCommand(this.pressMeta);
- }
-
- }
-
- public void this_commandPerformed(Command var1, Displayable var2) {
- if (var1 == this.disconnectCommand) {
- this.isRunning = false;
- this.rfb.close();
- } else if (var1 == this.textCommand) {
- this.keyMode = 2;
- } else if (var1 == this.cursorCommand) {
- this.keyMode = 1;
- } else if (var1 == this.imageCommand) {
- this.keyMode = 3;
- } else if (var1 == this.numericCommand) {
- this.keyMode = 5;
- } else if (var1 == this.arrowCommand) {
- this.keyMode = 4;
- } else if (var1 == this.textAreaCommand) {
- this.parent.display.setCurrent(this.textArea);
- } else if (var1 == this.specialCharsCommand) {
- this.parent.display.setCurrent(this.specialCharsList);
- } else if (var1 == this.pressCtrl) {
- this.isCtrlPressed = true;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65507, true);
- } catch (IOException var9) {
- }
- } else if (var1 == this.pressAlt) {
- this.isAltPressed = true;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65513, true);
- } catch (IOException var8) {
- }
- } else if (var1 == this.pressMeta) {
- this.isMetaPressed = true;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65511, true);
- } catch (IOException var7) {
- }
- } else if (var1 == this.releaseCtrl) {
- this.isCtrlPressed = false;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65507, false);
- } catch (IOException var6) {
- }
- } else if (var1 == this.releaseAlt) {
- this.isAltPressed = false;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65513, false);
- } catch (IOException var5) {
- }
- } else if (var1 == this.releaseMeta) {
- this.isMetaPressed = false;
- this.doCommands();
-
- try {
- this.rfb.writeKeyEvent(65511, false);
- } catch (IOException var4) {
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- var1.setColor(16777215);
- var1.fillRect(0, 0, ((Canvas)this).getWidth(), ((Canvas)this).getHeight());
- if (this.paintImage == null) {
- var1.setColor(0);
- int var2 = var1.getFont().getHeight();
-
- for(int var3 = 0; var3 < this._status.size(); ++var3) {
- var1.drawString((String)this._status.elementAt(var3), 0, var3 * var2, 20);
- }
- } else {
- try {
- var1.drawImage(this.paintImage, 0, 0, 20);
- if (this.currentLetter != '\uffff') {
- var1.setColor(16777215);
- var1.fillRect(((Canvas)this).getWidth() - 21, ((Canvas)this).getHeight() - 21, 20, 20);
- var1.setColor(0);
- var1.drawRect(((Canvas)this).getWidth() - 21, ((Canvas)this).getHeight() - 21, 20, 20);
- Font var5 = Font.getFont(32, 1, 16);
- var1.setFont(var5);
- var1.setColor(16711680);
- var1.drawChar(this.currentLetter, ((Canvas)this).getWidth() - 20 + (20 - var5.charWidth(this.currentLetter)) / 2, ((Canvas)this).getHeight() - 20 + (20 - var5.getHeight()) / 2, 20);
- }
- } catch (Exception var4) {
- }
- }
-
- var1.setColor(16711680);
- var1.fillRect(this.cursorX, this.cursorY, 3, 3);
- }
-
- public void processNormalProtocol() throws IOException {
- this.isRunning = true;
- ((Displayable)this).setCommandListener(new 1(this));
- this.doCommands();
- System.out.println("Sending request");
- this.incremental = false;
- this.rfb.writeFramebufferUpdateRequest(this.deltaX, this.deltaY, ((Canvas)this).getWidth(), ((Canvas)this).getHeight(), this.incremental);
- this.needToResetClip = false;
-
- while(this.isRunning) {
- int var1 = this.rfb.readServerMessageType();
- switch (var1) {
- case 0:
- this.rfb.readFramebufferUpdate();
- int var2 = 0;
-
- for(; var2 < this.rfb.updateNRects; ++var2) {
- this.rfb.readFramebufferUpdateRectHdr();
- if (this.needToResetClip && this.rfb.updateRectEncoding != 0) {
- this.pig.setClip(0, 0, this.rfb.framebufferWidth, this.rfb.framebufferHeight);
- this.needToResetClip = false;
- }
-
- switch (this.rfb.updateRectEncoding) {
- case 0:
- this.drawRawRect(this.rfb.updateRectX, this.rfb.updateRectY, this.rfb.updateRectW, this.rfb.updateRectH);
- break;
- case 1:
- case 3:
- default:
- throw new IOException("Unknown RFB rectangle encoding " + this.rfb.updateRectEncoding);
- case 2:
- int var19 = this.rfb.is.readInt();
- int var21 = this.rfb.is.read();
- this.pig.translate(this.rfb.updateRectX, this.rfb.updateRectY);
- this.pig.setColor(this.toRGB(var21));
- this.pig.fillRect(0, 0, this.rfb.updateRectW, this.rfb.updateRectH);
-
- for(int var37 = 0; var37 < var19; ++var37) {
- int var24 = this.rfb.is.read();
- int var27 = this.rfb.is.readUnsignedShort();
- int var30 = this.rfb.is.readUnsignedShort();
- int var33 = this.rfb.is.readUnsignedShort();
- int var35 = this.rfb.is.readUnsignedShort();
- this.pig.setColor(this.toRGB(var24));
- this.pig.fillRect(var27, var30, var33, var35);
- }
-
- this.pig.translate(-this.rfb.updateRectX, -this.rfb.updateRectY);
- break;
- case 4:
- int var18 = this.rfb.is.readInt();
- int var20 = this.rfb.is.read();
- this.pig.translate(this.rfb.updateRectX, this.rfb.updateRectY);
- this.pig.setColor(this.toRGB(var20));
- this.pig.fillRect(0, 0, this.rfb.updateRectW, this.rfb.updateRectH);
-
- for(int var36 = 0; var36 < var18; ++var36) {
- int var23 = this.rfb.is.read();
- int var26 = this.rfb.is.read();
- int var29 = this.rfb.is.read();
- int var32 = this.rfb.is.read();
- int var34 = this.rfb.is.read();
- this.pig.setColor(this.toRGB(var23));
- this.pig.fillRect(var26, var29, var32, var34);
- }
-
- this.pig.translate(-this.rfb.updateRectX, -this.rfb.updateRectY);
- break;
- case 5:
- int var3 = 0;
- int var4 = 0;
-
- for(int var9 = this.rfb.updateRectY; var9 < this.rfb.updateRectY + this.rfb.updateRectH; var9 += 16) {
- for(int var10 = this.rfb.updateRectX; var10 < this.rfb.updateRectX + this.rfb.updateRectW; var10 += 16) {
- int var11 = 16;
- int var12 = 16;
- if (this.rfb.updateRectX + this.rfb.updateRectW - var10 < 16) {
- var11 = this.rfb.updateRectX + this.rfb.updateRectW - var10;
- }
-
- if (this.rfb.updateRectY + this.rfb.updateRectH - var9 < 16) {
- var12 = this.rfb.updateRectY + this.rfb.updateRectH - var9;
- }
-
- int var13 = this.rfb.is.read();
- if ((var13 & 1) != 0) {
- this.drawRawRect(var10, var9, var11, var12);
- } else {
- if (this.needToResetClip) {
- this.pig.setClip(0, 0, ((Canvas)this).getWidth(), ((Canvas)this).getHeight());
- this.needToResetClip = false;
- }
-
- if ((var13 & 2) != 0) {
- var3 = this.rfb.is.read();
- }
-
- this.pig.setColor(this.toRGB(var3));
- this.pig.fillRect(var10, var9, var11, var12);
- if ((var13 & 4) != 0) {
- var4 = this.rfb.is.read();
- }
-
- if ((var13 & 8) != 0) {
- int var14 = this.rfb.is.read();
- this.pig.translate(var10, var9);
- if ((var13 & 16) != 0) {
- for(int var15 = 0; var15 < var14; ++var15) {
- var4 = this.rfb.is.read();
- int var16 = this.rfb.is.read();
- int var17 = this.rfb.is.read();
- int var5 = var16 >> 4;
- int var6 = var16 & 15;
- int var7 = (var17 >> 4) + 1;
- int var8 = (var17 & 15) + 1;
- this.pig.setColor(this.toRGB(var4));
- this.pig.fillRect(var5, var6, var7, var8);
- }
- } else {
- this.pig.setColor(this.toRGB(var4));
-
- for(int var38 = 0; var38 < var14; ++var38) {
- int var39 = this.rfb.is.read();
- int var40 = this.rfb.is.read();
- int var22 = var39 >> 4;
- int var25 = var39 & 15;
- int var28 = (var40 >> 4) + 1;
- int var31 = (var40 & 15) + 1;
- this.pig.fillRect(var22, var25, var28, var31);
- }
- }
-
- this.pig.translate(-var10, -var9);
- }
- }
- }
- }
- }
- }
-
- this.rfb.writeFramebufferUpdateRequest(this.deltaX, this.deltaY, ((Canvas)this).getWidth(), ((Canvas)this).getHeight(), this.incremental);
- this.incremental = true;
- break;
- case 1:
- throw new IOException("Can't handle SetColourMapEntries message");
- case 2:
- System.out.print('\u0007');
- break;
- default:
- throw new IOException("Unknown RFB message type " + var1);
- }
-
- ((Canvas)this).repaint();
- ((Canvas)this).serviceRepaints();
- }
-
- }
-
- void drawRawRect(int var1, int var2, int var3, int var4) throws IOException {
- for(int var5 = var2; var5 < var2 + var4; ++var5) {
- for(int var6 = var1; var6 < var1 + var3; ++var6) {
- int var7 = this.rfb.is.read();
- this.pig.setColor(this.toRGB(var7));
- this.pig.fillRect(var6, var5, 1, 1);
- }
- }
-
- }
-
- public void pointerPressed(int var1, int var2) {
- System.out.println("Got pointer press");
- if (this.keyMode == 1) {
- this.cursorX = var1;
- this.cursorY = var2;
- this.cursorButton = 1;
- this.updateCursor();
- } else if (this.keyMode == 3) {
- this.pig.translate(this.deltaX, this.deltaY);
- if (var1 > 20 && var1 < ((Canvas)this).getWidth() - 20 && var2 < 20) {
- if (this.deltaY > ((Canvas)this).getHeight()) {
- this.deltaY -= ((Canvas)this).getHeight();
- } else {
- this.deltaY = 0;
- }
- }
-
- if (var1 > 20 && var1 < ((Canvas)this).getWidth() - 20 & var2 > ((Canvas)this).getHeight() - 20) {
- if (this.deltaY < this.rfb.framebufferHeight - 2 * ((Canvas)this).getHeight()) {
- this.deltaY += ((Canvas)this).getHeight();
- } else {
- this.deltaY = this.rfb.framebufferHeight - ((Canvas)this).getHeight();
- }
- }
-
- if (var1 < 20 && var2 > 20 && var2 < ((Canvas)this).getHeight() - 20) {
- if (this.deltaX > ((Canvas)this).getWidth()) {
- this.deltaX -= ((Canvas)this).getWidth();
- } else {
- this.deltaX = 0;
- }
- }
-
- if (var1 > ((Canvas)this).getWidth() - 20 && var2 > 20 && var2 < ((Canvas)this).getHeight() - 20) {
- if (this.deltaX < this.rfb.framebufferWidth - 2 * ((Canvas)this).getWidth()) {
- this.deltaX += ((Canvas)this).getWidth();
- } else {
- this.deltaX = this.rfb.framebufferWidth - ((Canvas)this).getWidth();
- }
- }
-
- this.pig.translate(-this.deltaX, -this.deltaY);
- this.incremental = false;
-
- try {
- this.rfb.writeFramebufferUpdateRequest(this.deltaX, this.deltaY, ((Canvas)this).getWidth(), ((Canvas)this).getHeight(), this.incremental);
- } catch (Exception var4) {
- ((Throwable)var4).printStackTrace();
- }
-
- ((Canvas)this).repaint();
- }
-
- }
-
- public void keyPressed(int var1) {
- if (this.keyMode == 1) {
- int var2 = ((Canvas)this).getGameAction(var1);
- if (var2 == 1 && this.cursorY > 0) {
- --this.cursorY;
- } else if (var2 == 6 && this.cursorY < ((Canvas)this).getHeight()) {
- ++this.cursorY;
- } else if (var2 == 2 && this.cursorX > 0) {
- --this.cursorX;
- } else if (var2 == 5 && this.cursorX < ((Canvas)this).getWidth()) {
- ++this.cursorX;
- } else if (var2 == 8) {
- this.cursorButton = 1;
- }
-
- this.updateCursor();
- this.cursorButton = 0;
- } else if (this.keyMode == 5) {
- this.keyReader.pushNumericKey(var1);
- } else if (this.keyMode == 2) {
- if (var1 == 35) {
- this.keyReader.toggleCaps();
- return;
- }
-
- if (var1 == 42) {
- var1 = 65293;
-
- try {
- this.rfb.writeKeyEvent(var1, true);
- } catch (IOException var5) {
- ((Throwable)var5).printStackTrace();
- }
-
- return;
- }
-
- this.keyReader.pushKey(var1);
- } else if (this.keyMode == 3) {
- this.pig.translate(this.deltaX, this.deltaY);
- int var9 = ((Canvas)this).getGameAction(var1);
- if (var9 == 1) {
- if (this.deltaY > ((Canvas)this).getHeight()) {
- this.deltaY -= ((Canvas)this).getHeight();
- } else {
- this.deltaY = 0;
- }
- }
-
- if (var9 == 6) {
- if (this.deltaY < this.rfb.framebufferHeight - 2 * ((Canvas)this).getHeight()) {
- this.deltaY += ((Canvas)this).getHeight();
- } else {
- this.deltaY = this.rfb.framebufferHeight - ((Canvas)this).getHeight();
- }
- }
-
- if (var9 == 2) {
- if (this.deltaX > ((Canvas)this).getWidth()) {
- this.deltaX -= ((Canvas)this).getWidth();
- } else {
- this.deltaX = 0;
- }
- }
-
- if (var9 == 5) {
- if (this.deltaX < this.rfb.framebufferWidth - 2 * ((Canvas)this).getWidth()) {
- this.deltaX += ((Canvas)this).getWidth();
- } else {
- this.deltaX = this.rfb.framebufferWidth - ((Canvas)this).getWidth();
- }
- }
-
- this.pig.translate(-this.deltaX, -this.deltaY);
- this.incremental = false;
-
- try {
- this.rfb.writeFramebufferUpdateRequest(this.deltaX, this.deltaY, ((Canvas)this).getWidth(), ((Canvas)this).getHeight(), this.incremental);
- } catch (Exception var7) {
- ((Throwable)var7).printStackTrace();
- }
-
- ((Canvas)this).repaint();
- } else if (this.keyMode == 4) {
- int var10 = ((Canvas)this).getGameAction(var1);
- char var3 = 0;
- switch (var10) {
- case 1:
- var3 = 'r';
- break;
- case 2:
- var3 = 'q';
- case 3:
- case 4:
- case 7:
- default:
- break;
- case 5:
- var3 = 's';
- break;
- case 6:
- var3 = 't';
- break;
- case 8:
- var3 = '-';
- }
-
- try {
- this.rfb.writeKeyEvent(var3, true);
- } catch (IOException var6) {
- ((Throwable)var6).printStackTrace();
- return;
- }
- }
-
- }
-
- public void keyRepeated(int var1) {
- this.keyPressed(var1);
- }
-
- public void updateCursor() {
- ((Canvas)this).repaint();
-
- try {
- this.rfb.writePointerEvent(this.cursorX + this.deltaX, this.cursorY + this.deltaY, this.cursorButton);
- if (this.cursorButton != 0) {
- this.rfb.writePointerEvent(this.cursorX + this.deltaX, this.cursorY + this.deltaY, 0);
- }
- } catch (IOException var2) {
- ((Throwable)var2).printStackTrace();
- }
-
- }
- }
-